package com.up1234567.unistarcloud.demo.web;

import com.up1234567.unistar.springcloud.discover.rest.UnistarRestTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import java.nio.charset.StandardCharsets;

@SpringBootApplication
@EnableDiscoveryClient(autoRegister = false)
@EnableFeignClients("com.up1234567.unistarcloud.demo.web.remote")
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Bean
    @Qualifier("restTemplate")
    public RestTemplate restTemplate() {
        RestTemplate restTemplate = new UnistarRestTemplate();
        restTemplate.getMessageConverters().forEach(m -> {
            if (m instanceof StringHttpMessageConverter) {
                ((StringHttpMessageConverter) m).setDefaultCharset(StandardCharsets.UTF_8);
            }
        });
        return restTemplate;
    }

}
